
#import "WebViewController.h"
#import "MainViewController.h"
@interface WebViewController ()

@end

@implementation WebViewController

-(void)loadView
{
    [super loadView];
    
    [self loadNavigationView];
    
    [self loadWebView];
    
    [self loadtabbarView];
}
-(void)loadNavigationView
{
    textfield=[[UITextField alloc]initWithFrame:CGRectMake(60, 12, 200, 24)];
    textfield.placeholder=@"请输入网址";
    textfield.backgroundColor=[UIColor whiteColor];
    textfield.delegate=self;
    textfield.borderStyle=UITextBorderStyleRoundedRect;
    textfield.keyboardType=UIKeyboardTypeURL;
    self.navigationItem.titleView = textfield;
    
    UIButton *gobutton= [UIButton buttonWithType:UIButtonTypeSystem];
    gobutton.frame=CGRectMake(320-2-60, 0, 44, 44);
    [gobutton setTitle:@"Go" forState:UIControlStateNormal];
    [gobutton addTarget:self action:@selector(goWEB) forControlEvents:UIControlEventTouchUpInside];
    [gobutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    gobutton.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:gobutton];
   
}

-(void)goWEB
{
    [self commonResginFirstResponder];
}

-(void)commonResginFirstResponder
{
    [textfield resignFirstResponder];//放弃第一响应者
    
    NSURL * url = [NSURL URLWithString:[@"http://" stringByAppendingString:textfield.text]];
    
    NSURLRequest * request = [NSURLRequest requestWithURL:url];
    
    [_webview loadRequest:request];
}

-(void)loadWebView
{
    _webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHeight-44)];

    _webview.delegate = self;
    NSURL * url = [NSURL URLWithString:[@"http://" stringByAppendingString:@"baidu.com"]];
	
	NSURLRequest * request = [NSURLRequest requestWithURL:url];
	
	[_webview loadRequest:request];
    
    [self.view addSubview:_webview];
}
-(void)loadtabbarView
{
    _footTabBar=[[UIImageView alloc]initWithFrame:CGRectMake(0, kDeviceHeight-44, kDeviceWidth, 44)];
    _footTabBar.image=[UIImage imageNamed:@"nav_bg_all"];
    _footTabBar.userInteractionEnabled=YES;
    _footTabBar.contentMode=UIViewContentModeScaleAspectFill;
    
    UIButton *forword2= [UIButton buttonWithType:UIButtonTypeSystem];
    forword2.frame=CGRectMake(50+88*2, 0, 44, 44);
    [forword2 setTitle:@"向前" forState:UIControlStateNormal];
    [forword2 addTarget:self action:@selector(goForward2) forControlEvents:UIControlEventTouchUpInside];
    [_footTabBar addSubview:forword2];
    
    UIButton *back1= [UIButton buttonWithType:UIButtonTypeSystem];
    back1.frame=CGRectMake(50, 0, 44, 44);
    [back1 setTitle:@"向后" forState:UIControlStateNormal];
    [back1 addTarget:self action:@selector(goBack1) forControlEvents:UIControlEventTouchUpInside];
    [_footTabBar addSubview:back1];
    
    UIButton *refresh3= [UIButton buttonWithType:UIButtonTypeSystem];
    refresh3.frame=CGRectMake(50+88, 0, 44, 44);
    [refresh3 setTitle:@"刷新" forState:UIControlStateNormal];
    [refresh3 addTarget:self action:@selector(refresh3) forControlEvents:UIControlEventTouchUpInside];
    [_footTabBar addSubview:refresh3];
    
 
    [self.view addSubview:_footTabBar];
}
-(void)goBack1
{
    [_webview goBack];
}
-(void)goForward2
{
    [_webview goForward];
}
-(void)refresh3
{
    [_webview reload];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationItem.hidesBackButton = YES;
    
    self.tabBarController.tabBar.hidden = YES;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    
}
//webViewDidFinishLoad方法 返回的主要都是HTML代码 可以通过该方法给用户一些提示如成功或失败
- (void)webViewDidFinishLoad: (UIWebView *) webView
{
	NSLog(@"%@", [webView stringByEvaluatingJavaScriptFromString:
				  @"document.body.innerHTML"]);
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self commonResginFirstResponder];
    return YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
